const sd = new Map()
sd.set('load',true)
PlayerEvents.tick(event =>{
    const player = event.player
    const x =parseInt(player.x);const z =parseInt(player.z)
    if(player.level.dimension === 'minecraft:the_end' && player.y >= 550){
        if(x>=0 && z>= 0){
            const x=75;const z=75
            event.server.runCommandSilent('execute in minecraft:the_end run tp @e[type=ad_astra:lander] 75 500 75')
            event.server.runCommandSilent(`execute in minecraft:the_end run fill ${x - 2} 50 ${z - 2} ${x + 2} 50 ${z + 2} minecraft:obsidian`);}
        else if(x>0 && z< 0){
            const x=75;const z=-75
            event.server.runCommandSilent('execute in minecraft:the_end run tp @e[type=ad_astra:lander] 75 500 -75')
            event.server.runCommandSilent(`execute in minecraft:the_end run fill ${x - 2} 50 ${z - 2} ${x + 2} 50 ${z + 2} minecraft:obsidian`);}
        else if(x<0 && z>= 0){
            const x=-75;const z=75
            event.server.runCommandSilent('execute in minecraft:the_end run tp @e[type=ad_astra:lander] -75 500 75')
            event.server.runCommandSilent(`execute in minecraft:the_end run fill ${x - 2} 50 ${z - 2} ${x + 2} 50 ${z + 2} minecraft:obsidian`);}
        else if(x<0 && z< 0){
            const x=-75;const z=-75
            event.server.runCommandSilent('execute in minecraft:the_end run tp @e[type=ad_astra:lander] -75 500 -75')
            event.server.runCommandSilent(`execute in minecraft:the_end run fill ${x - 2} 50 ${z - 2} ${x + 2} 50 ${z + 2} minecraft:obsidian`);}
        
    }
});
//用来控制死亡不掉落，如果想节省资源可以后期删掉
LevelEvents.tick(event => {
    const {server} = event
    const seconds = Math.floor(event.level.getTime()/20)
    if(seconds % 40 === 0){
        const day = Math.floor(seconds/1440)
        if (seconds === 10080) {
            server.runCommandSilent('gamerule keepInventory false')
            server.runCommandSilent(`tellraw @a [{"text":"第7天结束，死亡掉落已恢复","color":"yellow"}]`)
            sd.set('load',false)
        };
        if(sd.get('load')){
            server.runCommandSilent(`tellraw @a {"text":"存档游玩时长：${day} day"}`)
            if (day < 7) {
                server.runCommandSilent('gamerule keepInventory true')
                server.runCommandSilent(`tellraw @a [{"text":"死亡不掉落已启动","color":"green"}]`)}
            else if(day >= 7){
                server.runCommandSilent('gamerule keepInventory true')
                server.runCommandSilent(`tellraw @a [{"text":"死亡不掉落已关闭","color":"yellow"}]`)
            }
        sd.set('load',false)
    }}
});

const version = 'Beta-0.9'
PlayerEvents.loggedIn(event =>{
    const {player,server} = event
    server.runCommandSilent('gamerule doTraderSpawning false')
    server.runCommandSilent(`tellraw ${player.name.string} [{"text":"${player.name.string},","color":"green"},{"text":"欢迎游玩TFC-REturn!","color":"white"}]`)
    server.runCommandSilent(`tellraw ${player.name.string} [{"text":"当前游玩版本"},{"text":"${version}","color":"yellow"},{"text":"。如果你有任何建议与反馈，或者想来水群，欢迎加入 QQ群"},{"text":"1034308053","color":"green"}]`)
})

BlockEvents.rightClicked('tfc:firepit' , event => {
    if(event.player.getMainHandItem().hasTag('tfc:hammers')){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
        const blockBelow = event.level.getBlock(x, y-1, z);
        if (blockBelow.id !== 'minecraft:coal_block') return;
        event.server.runCommandSilent(`setblock ${x} ${y - 1} ${z} minecraft:campfire`);
        event.getItem().setDamageValue(event.player.getMainHandItem().damageValue+25)
        if(event.player.getMainHandItem().getMaxDamage() <= event.player.getMainHandItem().damageValue){   
            event.player.setMainHandItem('minectaft:air')
            event.server.runCommandSilent(`playsound minecraft:block.anvil.destroy player ${event.player}`)
        }
        event.cancel()
    }
    
});
BlockEvents.rightClicked('createnuclear:enriched_soul_soil' , event => {
    const it = event.player.getMainHandItem()
    if(event.player.getMainHandItem() === 'minecraft:flint_and_steel'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();

        event.server.runCommandSilent(`setblock ${x} ${y} ${z} createnuclear:enriching_campfire`);
        event.getItem().setDamageValue(it.damageValue+1)
    }
});//召唤村民
EntityEvents.spawned('minecraft:lightning_bolt',event =>{
    const{entity,level,server}=event;
    const x=Math.floor(entity.x);const y=Math.floor(entity.y);const z=Math.floor(entity.z);
    if(level.getBlock(x,y-1,z).id !== 'goety:awakened_emerald_block') return;
    server.runCommandSilent(`setblock ${x} ${y-1} ${z} minecraft:air`)
    server.runCommandSilent(`summon minecraft:villager ${x} ${y-5} ${z} {VillagerData:{profession:"minecraft:nitwit"}}`)
})
//
BlockEvents.rightClicked('immersiveengineering:heavy_engineering' , event => {
    if(event.player.getMainHandItem() ==='immersiveengineering:hammer'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
        if (event.level.getBlock(x, y+1, z).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y+1, z+1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y+1, z-1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y+1, z+1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y+1, z+1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y+1, z).id !== 'anvilcraft:reinforced_concrete_white_slab') return;
        if (event.level.getBlock(x-1, y+1, z).id !== 'anvilcraft:reinforced_concrete_white_slab') return;
        if (event.level.getBlock(x, y+1, z+1).id !== 'anvilcraft:reinforced_concrete_white_slab') return;
        if (event.level.getBlock(x, y+1, z-1).id !== 'anvilcraft:reinforced_concrete_white_slab') return;
        event.server.runCommandSilent(`fill ${x - 1} ${y + 1} ${z - 1} ${x + 1} ${y + 1} ${z + 1} minecraft:air`);
        event.server.runCommandSilent(`setblock ${x} ${y + 1} ${z} ad_astra:launch_pad`);
        event.server.runCommandSilent(`setblock ${x} ${y } ${z} immersiveengineering:sheetmetal_steel`);
        event.getItem().setDamageValue(event.player.getMainHandItem().damageValue+1)
        if(event.player.getMainHandItem().getMaxDamage() <= event.player.getMainHandItem().damageValue){   
            event.player.setMainHandItem('minectaft:air')
            event.server.runCommandSilent(`playsound minecraft:block.anvil.destroy player ${event.player}`)
        }
    }
});
//
BlockEvents.rightClicked('minecraft:gold_block' , event => {
    if(event.player.getMainHandItem() === 'enderio:z_logic_controller'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
        const it = event.player.getMainHandItem()
        event.server.runCommandSilent(`setblock ${x} ${y} ${z} minecraft:air`)
        event.item.shrink(1)
        event.server.runCommandSilent(`summon mobz:tank_zombie ${x+5} ${y} ${z}`)
        event.server.runCommandSilent(`summon mobz:tank_zombie ${x-5} ${y} ${z}`)
        event.server.runCommandSilent(`summon mobz:tank_zombie ${x} ${y} ${z+5}`)
        event.server.runCommandSilent(`summon mobz:tank_zombie ${x} ${y} ${z-5}`)
        event.server.runCommandSilent(`particle goety:wraith ${x} ${y} ${z} 3 3 3 1 300`)
        currentServer.runCommandSilent(`summon mobz:boss_zombie ${x} ${y} ${z}`)
        currentServer.runCommandSilent(`particle goety:wraith ${x} ${y} ${z} 3 3 3 1 700`)
        currentServer.runCommandSilent(`playsound minecraft:entity.wither.spawn player @a ${x} ${y} ${z} 1 0.2`)
    }});
    //
BlockEvents.rightClicked('goety:pedestal{Inventory:{Items:[{id:"goety:soul_candlestick",Count:1}]}}' , event => {
    if(event.player.getMainHandItem() === 'musketmod:musket'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
        const it = event.player.getMainHandItem()
        event.server.runCommandSilent(`setblock ${x} ${y} ${z} minecraft:air`)
        event.item.shrink(1)
        event.server.runCommandSilent(`summon mobz:nether_skeleton ${x+2} ${y} ${z+2}`)
        event.server.runCommandSilent(`summon mobz:overgrown_skeleton ${x-2} ${y} ${z+2}`)
        event.server.runCommandSilent(`summon mobz:overgrown_skeleton ${x+1} ${y} ${z+2}`)
        event.server.runCommandSilent(`summon mobz:nether_skeleton ${x-1} ${y} ${z+2}`)
        event.server.runCommandSilent(`summon mobz:boss_skeleton ${x} ${y} ${z} {CustomName:'{"text":"色欲化身"}',Health:150f,Attributes:[{Name:"generic.max_health",Base:150f}]}`)
        event.server.runCommandSilent(`item replace entity @e[name="色欲化身",distance=..3] armor.chest with goety:black_iron_chestplate{Enchantments:[{id: "minecraft:protection", lvl: 5}, {id: "minecraft:unbreaking", lvl: 4}, {id: "minecraft:binding_curse", lvl: 999}]}`)
        event.server.runCommandSilent(`item replace entity @e[name="色欲化身",distance=..3] armor.head with goety:black_iron_helmet`)
        event.server.runCommandSilent(`item replace entity @e[name="色欲化身",distance=..3] weapon with musketmod:musket`)
        event.server.runCommandSilent(`particle goety:wraith ${x} ${y} ${z} 3 3 3 1 700`)
        event.server.runCommandSilent(`playsound minecraft:item.goat_horn.sound.6 player @a ${x} ${y} ${z} 1 0.9`)
        event.cancel()
    }
});
// PlayerEvents.tick(event => {
// const player = event.player
// const offhandItem = player.offhandItem
// if (offhandItem.id === 'kubejs:wrath') {
//     // 如果副手持有物品，给予玩家 Buff
//     player.potionEffects.add('crust:vulnerability', 100, 0, false, false) 
//     player.potionEffects.add('minecraft:mining_fatigue', 100, 0, false, false)
//     player.potionEffects.add('goety:wild_rage', 100, 0, false, false) 
//   } 
// if (offhandItem.id === 'kubejs:greed') {
//     player.potionEffects.add('minecraft:blindness', 100, 0, false, false) // 持续时间 100 ticks (5秒), 等级 1
//     player.potionEffects.add('minecraft:haste', 100, 0, false, false)
//     player.potionEffects.add('minecraft:darkness', 100, 0, false, false)  
//     }  
// if (offhandItem.id === 'kubejs:pride') {
//     player.potionEffects.add('minecraft:regeneration', 100, 0, false, false) // 持续时间 100 ticks (5秒), 等级 1
//     player.potionEffects.add('cofh_core:wrenched', 100, 0, false, false) 
//     player.potionEffects.add('minecraft:weakness', 100, 4, false, false) 
//     player.potionEffects.add('minecraft:slowness', 100, 255, false, false) 
//     player.potionEffects.add('crust:weight ', 100, 255, false, false) 
//     } 
// if (offhandItem.id === 'kubejs:gluttony') {
//     player.potionEffects.add('tfc:thirst', 100, 0, false, false) // 持续时间 100 ticks (5秒), 等级 1
//     player.potionEffects.add('minecraft:hunger', 100, 1, false, false) 
//     player.potionEffects.add('goety:corpse_eater', 100, 0, false, false) 
//     player.potionEffects.add('cofh_core:panacea', 100, 0, false, false)
//     }
// if (offhandItem.id === 'kubejs:envy') {
//     player.potionEffects.add('cofh_core:enderference', 100, 0, false, false) // 持续时间 100 ticks (5秒), 等级 1
//     player.potionEffects.add('cofh_core:clarity', 100, 0, false, false) 
//     player.potionEffects.add('tfc:exhausted', 100, 0, false, false) 
//     player.potionEffects.add('goety:wanegoety:wane', 100, 0, false, false)
//     }
// if (offhandItem.id === 'kubejs:lust') {
//     player.potionEffects.add('tfc:thirst', 100, 0, false, false) // 持续时间 100 ticks (5秒), 等级 1
//     player.potionEffects.add('minecraft:speed', 100, 0, false, false) 
//     player.potionEffects.add('cofh_core:love', 100, 0, false, false) 
//     } 
// if (offhandItem.id === 'kubejs:sloth') {
//     player.potionEffects.add('minecraft:resistance', 100, 0, false, false) // 持续时间 100 ticks (5秒), 等级 1
//     player.potionEffects.add('minecraft:slowness', 100, 2, false, false) 
//     } 
// });
  // 定义正确的物品顺序
  const correctOrder = [
    'kubejs:gluttony',         // 第1个物品
    'kubejs:lust',    // 第2个物品
    'kubejs:sloth',       // 第3个物品
    'kubejs:envy',       // 第4个物品
    'kubejs:wrath',      // 第5个物品
    'kubejs:greed',  // 第6个物品
    'kubejs:pride'    // 第7个物品
  ];
//制作七罪地球仪
const playerProgress = new Map();
BlockEvents.rightClicked('ad_astra:earth_globe',event => {
    const { player, hand, block } = event;
    if (hand !== 'MAIN_HAND') return;
    const heldItem = player.mainHandItem;
    const heldItemId = heldItem.id;
    const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
    let progress = playerProgress.get(player.id) || 0;
    if (heldItemId === correctOrder[progress]) {
        progress++;
        if (progress === correctOrder.length) {
            player.tell(`注入完成！`);
            player.server.runCommandSilent(`summon item ${x} ${y} ${z} {Item:{id:"kubejs:sins_of_globe",Count:1b}}`);
            event.server.runCommandSilent(`setblock ${x} ${y} ${z} minecraft:air`)
            progress = 0; // 重置进度
        }
        playerProgress.set(player.id, progress);
        player.tell(`成功注入,它还没有满足${progress}/${correctOrder.length}`);
    }else if (heldItem === 'minecraft:air'){return}
    else {
        playerProgress.set(player.id, 0);
        player.tell('顺序错误，已重置进度！');
}
});
//制作锻造模板
const jewrProgress = new Map();
const temitem = [
    'anvilcraft:royal_steel_ingot', 
    'anvilcraft:sapphire',
    'tfc:powder/diamond',
    'tfc:gem_saw',
  ];
BlockEvents.rightClicked('anvilcraft:jewelcrafting_table',event => {
    const { player, hand, block } = event;
    if (hand !== 'MAIN_HAND') return;
    const heldItem = player.mainHandItem;
    const heldItemId = heldItem.id;
    const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
    let progress = jewrProgress.get(player.id) || 0;
    if (heldItemId === temitem[progress]) {
        progress++;
        if(progress < temitem.length-1 || heldItem.count >= 4){
            heldItem.setCount(heldItem.count-4)}
        else if (progress === temitem.length-1){
            heldItem.setCount(heldItem.count-1)}
        else if (progress === temitem.length) {
            player.tell(`制作成功！`);
            heldItem.setDamageValue(heldItem.damageValue+1)
            player.server.runCommandSilent(`summon item ${x} ${y+1} ${z} {Item:{id:"anvilcraft:royal_steel_upgrade_smithing_template",Count:1b}}`);
            player.server.runCommandSilent(`particle minecraft:scrape ${x} ${y+1} ${z} 1 1 1 0.33 10`)
            progress = 0;}
        jewrProgress.set(player.id, progress);
        if (progress === temitem.length-1){
            player.tell(`材料安放完毕`);
        }
        else if(progress !== 0){
            player.tell(`顺序正确${progress}/${temitem.length-1}`);
        }
    } else if (heldItem === 'minecraft:air'){player.tell('按顺序放入物品进行合成');event.cancel();return}
    else {
        player.tell('顺序错误!');
        event.cancel()
}
});
BlockEvents.rightClicked('immersiveengineering:heavy_engineering' , event => {
    if(event.player.getMainHandItem() ==='immersiveengineering:hammer'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();

        if (event.level.getBlock(x, y-1, z).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x+1, y-1, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-1, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-1, z+1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-1, z-1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-2, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y-2, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-2, z+1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-2, z-1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-2, z-1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y-2, z-1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-2, z+1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y-2, z+1).id !== 'immersiveengineering:slab_sheetmetal_steel') return;
        event.server.runCommandSilent(`fill ${x - 1} ${y} ${z - 1} ${x + 1} ${y - 2} ${z + 1} minecraft:air`);
        event.server.runCommandSilent(`summon minecraft:item ${x} ${y} ${z} {Item:{id:"ad_astra:rocket_fin",Count:2b,Damage:0s}}`);
        event.getItem().setDamageValue(event.player.getMainHandItem().damageValue+1)
        if(event.player.getMainHandItem().getMaxDamage() <= event.player.getMainHandItem().damageValue){   
            event.player.setMainHandItem('minectaft:air')
            event.server.runCommandSilent(`playsound minecraft:block.anvil.destroy player ${event.player}`)
        }
    }
})
BlockEvents.rightClicked('immersiveengineering:heavy_engineering' , event => {
    if(event.player.getMainHandItem() ==='immersiveengineering:hammer'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
        if (event.level.getBlock(x, y+1, z).id !== 'minecraft:lightning_rod') return;
        if (event.level.getBlock(x, y-1, z).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x, y-2, z).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x, y-3, z).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x+1, y-1, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-1, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-1, z+1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-1, z-1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-2, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y-2, z).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-2, z+1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x, y-2, z-1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-2, z-1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y-2, z-1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x+1, y-2, z+1).id !== 'immersiveengineering:sheetmetal_steel') return;
        if (event.level.getBlock(x-1, y-2, z+1).id !== 'immersiveengineering:sheetmetal_steel') return; 
        if (event.level.getBlock(x-1, y-3, z+1).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x-1, y-3, z+1).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x-1, y-3, z-1).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x+1, y-3, z-1).id !== 'immersiveengineering:steel_scaffolding_standard') return;
        if (event.level.getBlock(x, y-3, z-1).id !== 'anvilcraft:reinforced_concrete_black') return;
        if (event.level.getBlock(x, y-3, z+1).id !== 'anvilcraft:reinforced_concrete_black') return;
        if (event.level.getBlock(x-1, y-3, z).id !== 'anvilcraft:reinforced_concrete_black') return;
        if (event.level.getBlock(x+1, y-3, z).id !== 'anvilcraft:reinforced_concrete_black') return;
        event.server.runCommandSilent(`fill ${x - 1} ${y+1} ${z - 1} ${x + 1} ${y - 3} ${z + 1} minecraft:air`);
        event.server.runCommandSilent(`summon minecraft:item ${x} ${y} ${z} {Item:{id:"ad_astra:rocket_nose_cone",Count:1b,Damage:0s}}`);
        event.getItem().setDamageValue(event.player.getMainHandItem().damageValue+1)
        if(event.player.getMainHandItem().getMaxDamage() <= event.player.getMainHandItem().damageValue){   
            event.player.setMainHandItem('minectaft:air')
            event.server.runCommandSilent(`playsound minecraft:block.anvil.destroy player ${event.player}`)
        }
    }
});
BlockEvents.rightClicked('minecraft:zombie_head' , event => {
    if(event.player.getMainHandItem('minecraft:potion{Potion: "minecraft:strength"}')){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();
        event.server.runCommandSilent(`summon  ${x} ${y} ${z} mobz:bigboss`);{   
            event.player.setMainHandItem('minectaft:air')
            event.server.runCommandSilent(`playsound minecraft:block.anvil.destroy player ${event.player}`)
        }
    }
});
BlockEvents.rightClicked('minecraft:wither_skeleton_skull' , event => {
    if(event.player.getMainHandItem() ==='goety:mystic_core'){
        const x = event.getBlock().getX(), y = event.getBlock().getY(), z = event.getBlock().getZ();

        if (event.level.getBlock(x, y-1, z).id !== 'goety:reinforced_redstone_block') return;
        if (event.level.getBlock(x+1, y-1, z+1).id !== 'goety:reinforced_redstone_block') return;
        if (event.level.getBlock(x+1, y-1, z-1).id !== 'goety:reinforced_redstone_block') return;
        if (event.level.getBlock(x-1, y-1, z+1).id !== 'goety:reinforced_redstone_block') return;
        if (event.level.getBlock(x-1, y-1, z+1).id !== 'goety:reinforced_redstone_block') return;
        if (event.level.getBlock(x+1, y-1, z).id !== 'minecraft:redstone_block') return;
        if (event.level.getBlock(x-1, y-1, z).id !== 'minecraft:redstone_block') return;
        if (event.level.getBlock(x, y-1, z+1).id !== 'minecraft:redstone_block') return;
        if (event.level.getBlock(x, y-1, z-1).id !== 'minecraft:redstone_block') return;
        event.server.runCommandSilent(`fill ${x - 1} ${y} ${z - 1} ${x + 1} ${y - 1} ${z + 1} minecraft:air`);
        event.server.runCommandSilent(`summon goety:hostile_redstone_monstrosity ${x} ${y} ${z}`);
    }
});
ItemEvents.rightClicked('bsa:bone/fishing_rod',event =>{
    const {player,server} = event;
    const item = player.getMainHandItem()
     // 获取玩家坐标并转换为 BlockPos 对象
    const x = Math.floor(player.x)
    const y = Math.floor(player.y)
    const z = Math.floor(player.z)
    const pos = new BlockPos(x,y,z);
    const dx =  Math.floor((Math.random()-0.5)*5+(Math.random()-0.5)*15)
    const dz =  Math.floor((Math.random()-0.5)*5+(Math.random()-0.5)*15)

    const biome = player.level.getBiome(pos).unwrap().left().get().location().toString();
    // 获取生物群系并解析为 ResourceLocation 字符串
    if((biome === 'tfc:deep_ocean' || biome === 'tfc:deep_ocean_trench' )&& Math.random() < 0.01 && item.bait !== null){
        server.runCommandSilent(`summon minecraft:elder_guardian ${x+dx} ${y-5} ${z+dz}`)
    }
})
BlockEvents.broken(event =>{
    const {block} = event
    if(Math.random() < 0.05&& block.hasTag('dynamictrees:branches')){
        event.player.runCommandSilent('give @s tfc_lumberjack:sawdust')
        event.player.tell('你获得了一个锯末！')
    }
})
// EntityEvents.attacker(event =>{
//         const { damage,source, entity} = event;
//         // 获取攻击者
//         const attacker = source.getEntity();
//         if (!attacker) return;
//         // 获取武器（支持近战和远程）
//         let weapon;
//         if (source.isProjectile()) {
//             // 如果是投射物，获取发射的武器
//             weapon = attacker.getProjectileWeapon();
//         } else {
//             // 近战武器
//             weapon = attacker.getMainHandItem();
//         }
//         // 检查穿透附魔
//         if (weapon && weapon.hasEnchantment('kubejs:penetration')) {
//             const level = weapon.getEnchantmentLevel('kubejs:penetration');
//             const penetrationrate = level * 0.1;
//             const armorModifier = new DamageModifier('armor_penetration', {
//                 armor: entity.getArmorValue() * (1 - penetrationrate)
//             });
            
//             event.addDamageModifier(armorModifier);

//     }
// })